package com.neu.api.controller.admin;

import com.neu.api.dto.CourseDTO;
import com.neu.api.pojo.Course;
import com.neu.api.query.CourseQuery;
import com.neu.api.service.CourseService;
import com.neu.api.utils.PageResult;
import com.neu.api.utils.Result;
import com.neu.api.vo.CourseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "课程接口")
@RestController("portalCourseController")
@RequestMapping("/admin/course")
public class CourseController {
    @Resource
    CourseService courseService;




    @ApiOperation("添加课程")
    @PostMapping
//    public Result add(@RequestBody CourseDTO courseDTO){
    public Result add(CourseDTO courseDTO){




        System.out.println("courseDto " + courseDTO);
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

        courseService.add(courseDTO);
        return Result.ok("课程添加成功");
    }


    @ApiOperation("编辑课程")
    @PutMapping("/{id}")
    public Result update(@PathVariable int id,CourseDTO courseDTO){ //@RequestBody将前端传递的json格式的请求参数转为对象
        courseService.update(id,courseDTO);
        return Result.ok("课程修改成功");
    }


    @ApiOperation("查询课程")
    @GetMapping
    public Result<List<CourseVO>> find(CourseQuery courseQuery){ //courseQuery封装了查询的条件

        PageResult<CourseVO> page = courseService.find(courseQuery);

        return Result.ok("查询课程成功",page.getList(),page.getTotal());
    }


    @ApiOperation("删除课程")
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable int id){
        courseService.deleteById(id);
        return Result.ok("删除课程成功");
    }

    @ApiOperation("按ID查询单个课程")
    @GetMapping("/{id}")
    public Result findById(@PathVariable int id){
        CourseVO courseVO = courseService.findById(id);
        return Result.ok("查询单个课程成功",courseVO);
    }


}
//@Api(tags = "店铺接口")
//@RestController
//@RequestMapping("/app/shop")
//public class ShopController {
//
//
//    @Resource
//    CategoryService categoryService;
//
//
//
//    @ApiOperation("查询店铺菜品")
//    @GetMapping("/{shopId}/food")
//    public Result<List<CategoryDetailVO>> find(@PathVariable int shopId){
//
//        List<CategoryDetailVO> result = categoryService.findCategoryAndFood(shopId);
//        return Result.ok("成功",result);
//    }
//
//}